#include <bits/stdc++.h>
using namespace std;


class Solution
{
public:
    int Solve(int n)
    {
        int sum = 0;
        while (n)
        {
            sum += n % 10;
            n /= 10;
        }
        return sum;
    }
    int maximumSum(vector<int>& nums)
    {
        int ans = 0;
        unordered_map<int, int> cnt;
        for (int i = 0 ; i < nums.size(); i++)
        {
            int tmp = Solve(nums[i]);
            if (cnt.find(tmp) != cnt.end())
            {
                ans = max(ans, cnt[tmp] + tmp);
            }
            cnt[tmp] = max(cnt[tmp], nums[i]);//维护左
        }
        return ans;
    }
};